﻿package mortal.game.view.combinedServer
{
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.manager.window3d.*;
    import mortal.game.resource.*;
    import mortal.game.view.combinedServer.exp.*;
    import mortal.game.view.combinedServer.gift.*;
    import mortal.game.view.combinedServer.item.*;
    import mortal.game.view.combinedServer.rank.*;
    import mortal.game.view.combinedServer.recharge.*;
    import mortal.game.view.common.*;
    import mortal.mvc.interfaces.*;

    public class CombinedSerModule extends BaseWindow
    {
        protected var _leftBg:ScaleBitmap;
        protected var _tabBar:GTabBar2;
        private var _ary:Array;
        protected var _rightPanel:GSprite;
        protected var _rect3d:Rect3DObject;
        private static var _instance:CombinedSerModule;

        public function CombinedSerModule(param1:ILayer = null)
        {
            super(LayerManager.windowLayer3D);
            setSize(900, 600);
            this.title = "" + Language.getString(71377);
            return;
        }// end function

        protected function getActive11Ary() : Array
        {
            this._ary = [];
            this._ary.push(new CombinedSerTabData(CombinedSerTabData.Gift, CombinedSerGifts));
            this._ary.push(new CombinedSerTabData(CombinedSerTabData.RankRecharge, CombinedSerRechRank));
            this._ary.push(new CombinedSerTabData(CombinedSerTabData.DoubleExp, CombinedSerExpActive));
            return this._ary;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._leftBg = UIFactory.bg(4, 36, 202, 552, this, ImagesConst.PanelBg);
            this._tabBar = UICompomentPool.getUICompoment(GTabBar2);
            this._tabBar.cellRenderer = CombinedSerTabCell;
            this._tabBar.gap = 1;
            this._tabBar.cellWidth = 182;
            this._tabBar.cellHeight = 60;
            this._tabBar.direction = GBoxDirection.VERTICAL;
            this._tabBar.x = 10;
            this._tabBar.y = 39;
            this._tabBar.configEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.onSelectChange);
            this.addChild(this._tabBar);
            this._tabBar.dataProvider = this.getActive11Ary();
            this._tabBar.selectIndex = 0;
            this.updatePanel();
            this.checkRw();
            return;
        }// end function

        protected function onSelectChange(event:MuiEvent = null) : void
        {
            this.changeRect3d();
            this.updatePanel();
            return;
        }// end function

        private function changeRect3d() : void
        {
            var _loc_1:* = this._ary[this._tabBar.selectIndex];
            if (CombinedSerTabData.Boss == _loc_1.type)
            {
                if (this._rect3d)
                {
                    Rect3DManager.instance.disposeRect3d(this._rect3d);
                    this._rect3d = null;
                }
            }
            else if (this._rect3d == null)
            {
                this._rect3d = Rect3DManager.instance.registerWindow(true, new Rectangle(0, 0, 0, 0), this);
            }
            return;
        }// end function

        protected function updatePanel() : void
        {
            if (this._rightPanel)
            {
                this._rightPanel.dispose();
            }
            var _loc_1:* = this._tabBar.dataProvider[this._tabBar.selectIndex];
            this._rightPanel = UIFactory.getUICompoment(_loc_1.className);
            this._rightPanel.createDisposedChildren();
            UIFactory.setObjAttri(this._rightPanel, 211, 37, -1, -1, this);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            if (this._rect3d)
            {
                Rect3DManager.instance.disposeRect3d(this._rect3d);
                this._rect3d = null;
            }
            this._leftBg = null;
            this._tabBar.dispose();
            this._tabBar = null;
            this._rightPanel.dispose();
            this._rightPanel = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateRecharge() : void
        {
            if (this._rightPanel && this._rightPanel is CombinedSerRecharge)
            {
                (this._rightPanel as CombinedSerRecharge).updateInfo();
            }
            this.checkRw();
            return;
        }// end function

        private function checkRw() : void
        {
            return;
        }// end function

        public function updateRank() : void
        {
            if (this._rightPanel && this._rightPanel is CombinedSerRechRank)
            {
                (this._rightPanel as CombinedSerRechRank).updateRankInfo();
            }
            return;
        }// end function

        public static function get instance() : CombinedSerModule
        {
            if (!_instance)
            {
                _instance = new CombinedSerModule;
            }
            return _instance;
        }// end function

    }
}
